# 按照面向对象思想定义页面对象【PO】
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from base.page_base import BasePage
from tools import DriverTools


class RegisterPage(BasePage):

    # 静态数据：属性
    def __init__(self, driver):
        # 1.浏览器对象
        super().__init__(driver)
        # 手机号的元素定位信息
        self.phone = (By.ID, "phone")
        # 密码的元素定位信息
        self.password = (By.ID, "password")
        # 验证码
        self.code = (By.ID, "verifycode")
        # 短信验证码
        self.phone_code = (By.ID, "phone_code")
        # 短信验证码按钮
        self.get_phone_code = (By.ID, "get_phone_code")
        # 提交按钮
        self.submit = (By.CLASS_NAME, "lg-btn")
        # 获取注册结果
        self.res_success = (By.XPATH, '//*[@id="step3"]/div/div/h1')
        self.res_fail = (By.XPATH, '//*[@id="reg_form"]/div[1]')

    # 动态操作：方法
    def register(self, phone, pwd, code, phone_code="666666"):
        # 输入手机号
        self.fd_element(self.phone).send_keys(phone)
        # 输入密码
        self.fd_element(self.password).send_keys(pwd)
        # 输入验证码
        self.fd_element(self.code).send_keys(code)
        # 点击获取短信验证码
        self.fd_element(self.get_phone_code).click()
        time.sleep(2)
        # 输入短信验证码
        self.fd_element(self.phone_code).send_keys(phone_code)
        # 点击提交按钮
        self.fd_element(self.submit).click()

    def get_success_result(self):
        # 获取注册成功结果
        time.sleep(2)
        result = self.fd_element(self.res_success).text
        return result

    def get_fail_result(self):
        # 获取注册失败结果
        # time.sleep(2)
        result = self.fd_element(self.res_fail).text
        return result
